package com.zztpc.ljl.myapplication;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.List;


public class SecondFragment extends Fragment {


    public SecondFragment() {
        // Required empty public constructor
    }


    // TODO: Rename and change types and number of parameters
    public static SecondFragment newInstance() {
        SecondFragment fragment = new SecondFragment();
        Bundle args = new Bundle();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_second, container, false);
        BarChart bar = inflate.findViewById(R.id.barChar);
        List<BarEntry> data=new ArrayList<>();
        List<BarEntry> mDdata=new ArrayList<>();
        data.add(new BarEntry(1,5));
        data.add(new BarEntry(2,6));
        data.add(new BarEntry(3,7));
        data.add(new BarEntry(4,8));
        data.add(new BarEntry(5,9));

        mDdata.add(new BarEntry(3,1));
        mDdata.add(new BarEntry(4,2));
        mDdata.add(new BarEntry(5,3));
        mDdata.add(new BarEntry(6,4));
        mDdata.add(new BarEntry(7,5));

        BarDataSet barDataSet = new BarDataSet(data, "");
        BarDataSet mDbarDataSet = new BarDataSet(mDdata, "");
        BarData barData = new BarData(barDataSet);
        barData.addDataSet(mDbarDataSet);
        barDataSet.setColor(Color.RED);
        mDbarDataSet.setColor(Color.BLUE);
        bar.setData(barData);
        bar.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
        bar.getAxisRight().setEnabled(false);
        bar.getDescription().setEnabled(false);
        barData.groupBars(1f,0.6f,0);
       // barData.setBarWidth(0.5f);
        bar.getXAxis().setAxisMinimum(1);
        bar.getXAxis().setAxisMaximum(12);
        bar.getXAxis().setLabelCount(5,false);
        bar.getXAxis().setCenterAxisLabels(true);

        return inflate;
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {

    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

    }

    @Override
    public void onDetach() {
        super.onDetach();

    }


}
